layui.extend({
    selectN: '/layui_extends/selectN',
    selectM: '/layui_extends/selectM',
    baseConfig: "/js/pages/baseConfig"
}).use(['form', 'layer', 'laydate', 'table', 'laytpl', 'element', 'util', 'upload', 'selectN', 'selectM', 'baseConfig'], function () {

    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        table = layui.table,
        upload = layui.upload,
        laydate = layui.laydate,
        selectN = layui.selectN,
        baseConfig = layui.baseConfig,
        selectM = layui.selectM;
    var util = layui.util;

    //非管理员需要隐藏collaborateur和导入时间
    var hideCol = true;
    if (baseConfig.checkPrivalege(baseConfig.CONSUMER_LIST_ALL)) {
        hideCol = false;
    }

    var tableIns = table.render({
        elem: '#list',
        url: '/consumer/list/',
        cellMinWidth: 95,
        height: "full",
        page: true, //开启分页
        text: {none: "Aucun résultat"},
        limit: 100,
        limits: [100],
        //       toolbar: true, //开启头部工具栏，并为其绑定左侧模板
        //      defaultToolbar: ['filter'],
        totalRow: true, //开启合计行
        id: "listTable",
        cols: [[
            {type: "checkbox", fixed: "left", width: 50},
            {
                field: 'dateDeDepense', title: "Date de dépense", align: "center", templet: function (d) {
                    return baseConfig.formatDate(d.dateDeDepense);
                }
            },
            // {field: 'invoiceReviewTime', hide: hideCol, title: "Date de control", align:"center", templet : function( d){
            //     if( d.invoiceReviewTime){
            //         return baseConfig.formatDate( d.invoiceReviewTime);
            //     }else{
            //         return "/";
            //     }
            // }},
            {
                field: 'cooperativeSimpleName',
                title: "Fournisseur",
                width: 450,
                align: "center",
                templet: function (d) {
                    if (d.cooperativeSimpleName) {
                        return "<div style=\"overflow:hidden;white-space:nowrap;text-overflow:ellipsis;\">" + d.cooperativeSimpleName + "</div>";
                    } else {
                        return "<div style=\"overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color: red;\">" + d.fournisseur + "</div>";
                    }
                }
            },
            {field: 'jobNumber', title: "Collaborateurs", align: "center"},
            {
                field: 'carteIdentifiant', title: "Idantifiant", align: "center", templet: function (d) {
                    return "<div style=\"overflow:hidden;white-space:nowrap;text-overflow:ellipsis;\">" + d.carteIdentifiant + "</div>";
                }
            },
            {
                field: 'montantTTC',
                title: "DEBIT",
                align: "center",
                totalRow: true,
                totalRowText: "总计：",
                templet: function (d) {
                    if (d.montantTTC >= 0) {
                        var str = parseFloat(d.montantTTC).toFixed(2) + " €";
                        return "<div style='width: 40%;text-align: right;margin-right: 30%'>" + str + "</div>"
                    }
                    return "";
                }
            },
            {
                field: 'montantTTC',
                title: "CREDIT",
                align: "center",
                totalRow: true,
                totalRowText: "总计：",
                templet: function (d) {
                    if (d.montantTTC < 0) {
                        var str = -parseFloat(d.montantTTC).toFixed(2) + " €";
                        return "<div style='width: 40%;text-align: right;margin-right: 30%'>" + str + "</div>"
                    }
                    return "";
                }
            },
            // {field: 'memo', title: "Remarques",align:"center",templet : function( d){
            //     return "<div style=\"overflow:hidden;white-space:nowrap;text-overflow:ellipsis;\">" + d.memo + "</div>";
            // }},
            {
                title: 'État', fixed: "right", align: "center", templet: function (d) {
                    var str = "";
                    if (baseConfig.checkPrivalege(baseConfig.ALL)) {
                        str += "<a class=\"layui-btn layui-btn-xs layui-btn-primary\" lay-event=\"editCooperative\">修改</a>";
                    }
                    if (d.invoice) {
                        if (d.invoiceStatus == "PASS") {
                            // 蓝色
                            str += "<a class=\"layui-btn layui-btn-xs\" lay-event=\"viewInvoice\">Attaché</a>";
                        } else {
                            if (baseConfig.checkPrivalege(baseConfig.INVOICE_REVIEW)) {
                                if (d.invoice == "LOSE") {
                                    str += " <a class=\"layui-btn layui-btn-xs layui-btn-warm\" lay-event=\"reviewInvoice\">审核发票(发票遗失)</a>";
                                } else {
                                    str += " <a class=\"layui-btn layui-btn-xs layui-btn-warm\" lay-event=\"reviewInvoice\">审核发票</a>";
                                }
                            } else {
                                // 黄色
                                str += "<a class=\"layui-btn layui-btn-xs layui-btn-warm\" lay-event=\"uploadInvoice\"><span style='color: red'>Non renseigné</span></a>";
                            }
                        }
                    } else {
                        str += "<a class=\"layui-btn layui-btn-xs layui-btn-warm\" lay-event=\"uploadInvoice\">Non renseigné</a>";
                    }
                    return str;
                }
            }
        ]],
        response: {
            statusCode: 200 //规定成功的状态码，默认：0
        },
        parseData: function (res) { //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.count, //数据条数
                "data": res.data.data //解析数据列表
            };
        }
    });
    //加载日期选择框
    laydate.render({
        elem: '#dealStartTime',
        format: 'yyyy-MM-dd',
        trigger: 'click',
        type: "month",
        lang: 'en',
        max: 0,
        done: function (value, date) {
            $("input[name=dealStartTime]").val(value)
            $(".search_btn").click();
        }
    });
    laydate.render({
        elem: '#dealEndTime',
        format: 'yyyy-MM-dd',
        type: "month",
        lang: 'en',
        trigger: 'click',
        max: 0,
        done: function (value, date) {
            $("input[name=dealEndTime]").val(value)
            $(".search_btn").click();
        }
    });
    laydate.render({
        elem: '#reviewStartTime',
        format: 'yyyy-MM-dd',
        trigger: 'click',
        type: "month",
        lang: 'en',
        max: 0,
        done: function (value, date) {
            $("input[name=reviewStartTime]").val(value)
            $(".search_btn").click();
        }
    });
    laydate.render({
        elem: '#reviewEndTime',
        format: 'yyyy-MM-dd',
        lang: 'en',
        type: "month",
        trigger: 'click',
        max: 0,
        done: function (value, date) {
            $("input[name=reviewEndTime]").val(value)
            $(".search_btn").click();
        }
    });

    //处理权限相关
    handlePrivage();

    //输入money，将触发搜索事件
    $("input[name=money]").on("input propertychange", function (e) {
        $(".search_btn").click();
    });
    $("input[name=carteIdentifiant]").on("input propertychange", function (e) {
        $(".search_btn").click();
    });
    $("input[name=jobNumber]").on("input propertychange", function (e) {
        $(".search_btn").click();
    });
    $("input[name=carteIdentifiant]").on("input propertychange", function (e) {
        $(".search_btn").click();
    });
    $("input[name=cooperativeSimpleName]").on("input propertychange", function (e) {
        $(".search_btn").click();
    });
    form.on("select(invoiceStatus)", function () {
        $(".search_btn").click();
    });
    form.on("select(red)", function () {
        $(".search_btn").click();
    });
    /*
    //加载员工工号多选下拉框
    var importUserIdSelect = selectM({
        //元素容器【必填】
        elem: '#importUserIdDiv',
        //候选数据【必填】
        data: "/userAdmin/listForSelect",
        //最多选中个数，默认5
        max : 5,
        //input的name 不设置与选择器相同(去#.)
        name: 'importUserId',
        //值的分隔符
        delimiter: ',',
        tips: "ID",
        //候选项数据的键名
        field: {idName:'id',titleName:'jobNumber'}
    }); */

    //搜索
    $(".search_btn").on("click", function () {
        var paramJson = getSearchParam();
        //校验结束时间不能小于开始时间
        if (paramJson.dealStartTime && paramJson.dealEndTime) {
            var dealStartDate = new Date(paramJson.dealStartTime);
            var dealEndDate = new Date(paramJson.dealEndTime);
            if (dealStartDate.getTime() > dealEndDate.getTime()) {
                layer.msg("交易结束时间必须大于交易开始时间");
                return;
            }
        }
        if (paramJson.dealMonth && (paramJson.dealStartTime || paramJson.dealEndTime)) {
            layer.msg("起止时间和月份只能选择一种作为条件来查询");
            return;
        }
        if (paramJson.reviewStartTime && paramJson.reviewEndTime) {
            var reviewStartDate = new Date(paramJson.reviewStartTime);
            var reviewEndDate = new Date(paramJson.reviewEndTime);
            if (reviewStartDate.getTime() > reviewEndDate.getTime()) {
                layer.msg("审核结束时间必须大于审核开始时间");
                return;
            }
        }
        //获取当前页
        let recodePage = $(".layui-laypage-skip .layui-input").val();
        //获取当前页条数
        let recodeLimit = $(".layui-laypage-limits").find("option:selected").val();
        table.reload("listTable", {
            page: {
                curr: recodePage,
                limit: recodeLimit
            },
            where: paramJson
        })
    });

    //excal导出
    $("#download_invoice").on("click", function () {
        var index = layer.msg('导出中，请稍候....', {icon: 16, time: false, shade: 0.8});
        //获取到此时的查询条件
        var paramJson = getSearchParam();
        $.post("/consumer/exportInvoice", paramJson, function (res) {
            layer.close(index);
            if (res.code == 200) {
                var exportCount = res.data.exportCount;
                var filePath = res.data.filePath;
                top.layer.alert("导出成功");
                layer.confirm("导出成功,共导出[" + exportCount + "]条数据，确认下载文件？", function (confirmIndex) {
                    window.open(filePath);
                    layer.close(confirmIndex);
                });
            } else {
                top.layer.alert("导出失败");
            }
        });
    });
    $("#download_excel").on("click", function () {
        var index = layer.msg('导出中，请稍候....', {icon: 16, time: false, shade: 0.8});
        //获取到此时的查询条件
        var paramJson = getSearchParam();
        $.post("/consumer/exportAsExcel", paramJson, function (res) {
            layer.close(index);
            if (res.code == 200) {
                var exportCount = res.data.exportCount;
                var filePath = res.data.filePath;
                top.layer.alert("导出成功");
                layer.confirm("导出成功,共导出[" + exportCount + "]条数据，确认下载Excel文件？", function (confirmIndex) {
                    window.open(filePath);
                    layer.close(confirmIndex);
                });
            } else {
                top.layer.alert("导出失败");
            }
        });
    });

    $("#download_bank_statement").on("click", function () {
        var index = layer.msg('导出中，请稍候....', {icon: 16, time: false, shade: 0.8});
        //获取到此时的查询条件
        var paramJson = getSearchParam();
        $.post("/consumer/exportBankStatement", paramJson, function (res) {
            layer.close(index);
            if (res.code == 200) {
                var exportCount = res.data.exportCount;
                var filePath = res.data.filePath;
                top.layer.alert("导出成功");
                layer.confirm("导出成功,共导出[" + exportCount + "]条数据，确认下载Excel文件？", function (confirmIndex) {
                    window.open(filePath);
                    layer.close(confirmIndex);
                });
            } else {
                top.layer.alert(res.msg ? res.msg : "导出失败");
                // top.layer.alert( "导出失败");
            }
        });
    });

    //合并
    $("#merge_btn").on("click", function () {
        var checkStatus = table.checkStatus('listTable'),
            data = checkStatus.data;
        if (data.length > 0) {
            var ids = "";
            var jobNumber = data[0].jobNumber;
            for (var i = 0; i < data.length; i++) {
                if (data[i].invoice) {
                    layer.msg("已上传发票，不能参与合并");
                    return;
                }
                if (data[i].jobNumber != jobNumber) {
                    layer.msg("Collaborateurs不一致，不能参与合并");
                    return;
                }
                ids += data[i].id;
                if (i != data.length - 1) {
                    ids += ",";
                }
            }
            $.post("/consumer/merge", {
                ids: ids
            }, function (res) {
                if (res.code == 200) {
                    top.layer.msg("合并成功");
                    location.reload();
                } else {
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                }
            });
        } else {
            layer.msg("请选择需要合并的数据");
            return;
        }
    });
    //分拆
    $("#partition_btn").on("click", function () {
        var checkStatus = table.checkStatus('listTable'),
            data = checkStatus.data;
        if (data.length == 1) {
            if (data[0].invoice) {
                layer.msg("已上传发票，不能参与拆分");
                return;
            }
            var id = data[0].id;
            var total = data[0].montantTTC;
            var index = layui.layer.open({
                title: "拆分",
                type: 2,
                area: [800 + 'px', 400 + 'px'],
                shade: 0.4,
                btnAlign: 'r',
                id: "partition", //设定一个id，防止重复弹出
                content: "partition.html?id=" + id + "&total=" + total,
                success: function () {
                    setTimeout(function () {
                        layui.layer.tips('点击此处返回数据列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    }, 500);
                }
            });
        } else {
            layer.msg("请选择一条数据来做拆分");
            return;
        }
    });


    //获取浏览器最大高度，以防页面显示不完全
    var maxHeight = $(window).height();

    //打开上传发票页面
    function uploadInvoice(data, readonly) {
        if (data.invoiceStatus == "PASS" && !readonly) {
            top.layer.alert("发票已经审核通过，不能再次上传");
            return;
        }
        var customHouse = data.customHouse;
        if (!customHouse) {
            customHouse = "";
        }
        var invoiceImg = data.invoiceImg;
        if (!invoiceImg) {
            invoiceImg = "";
        }
        var index = layui.layer.open({
            title: "FACTURE",
            type: 2,
            area: [850 + 'px', (maxHeight - 10) + 'px'],
            shade: 0.4,
            btnAlign: 'r',
            id: "upload_invoice", //设定一个id，防止重复弹出
            content: "invoice.html?customHouse=" + customHouse + "&imgFilePath=" + invoiceImg,
            success: function () {
                var body = layui.layer.getChildFrame('body', index);
                if (data) {
                    body.find("input[name=id]").val(data.id).attr("readonly", readonly);//标识是修改还是新增
                    if (data.invoice) {
                        body.find("input[name=invoice]").val(data.invoice).attr("readonly", false);
                        body.find("input[name=invoiceImg]").val(data.invoiceImg).attr("readonly", false);
                    }
                    body.find("input[name=dateDeDepense]").val(data.dateDeDepense);
                    body.find("input[name=fournisseur]").val(data.fournisseur);
                    if (data.invoiceRate) {
                        if (data.invoiceRate == "other") {
                            body.find("#invoiceRateRadioThree").attr("checked", "checked");
                            body.find("input[name=invoiceMoney]").attr("readonly", false);
                        } else if (data.invoiceRate == "20%") {
                            body.find("#invoiceRateRadioOne").attr("checked", "checked");
                            body.find("input[name=invoiceMoney]").attr("readonly", true);
                        } else {
                            body.find("#invoiceRateRadioTwo").attr("checked", "checked");
                            body.find("input[name=invoiceMoney]").attr("readonly", true);
                        }
                    } else {
                        body.find("input[name=invoiceMoney]").attr("readonly", true);
                    }
                    if (readonly) {
                        body.find("input[name=invoiceMoney]").val(data.invoiceMoney).attr("readonly", false);
                    }
                    body.find("input[name=montantTTC]").val(parseFloat(data.montantTTC).toFixed(2));
                    if (readonly) {
                        body.find(".invoiceDiv").attr("style", "display:none;");
                        body.find("#submitDiv").hide();
                    }
                    form.render();
                }
                setTimeout(function () {
                    layui.layer.tips('点击此处返回发票列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500);
            }
        });
    }

    //上传excel文件
    upload.render({
        elem: '.import_excel_btn',
        url: '/file/upload?type=consumerImportExcel',
        method: "post",
        accept: "file",
        exts: "xlsx|xls",
        done: function (res) {
            if (res.code == 200) {
                var excelPath = res.data.filePath;
                var index = layer.msg('导入中，请稍候....', {icon: 16, time: false, shade: 0.8});
                //调用excel解析接口
                $.post("/consumer/importFromExcel2", {
                    "filePath": excelPath
                }, function (res) {
                    layer.close(index);
                    if (res.code == 200) {
                        var repeats = res.data.repeatDatas;
                        var successCount = res.data.successCount;

                        if (!repeats || repeats.length == 0) {
                            top.layer.alert("导入成功,本次成功导入[" + successCount + "]条数据");
                        }
                        tableIns.reload();
                    } else if (res.code == 60001) {
                        top.layer.alert("导卡号不包含");
                    } else if (res.code == 60003) {
                        top.layer.alert(res.msg);
                    } else if (res.code == 70001) {
                        top.layer.alert("日期出错");
                    } else {
                        top.layer.alert(res.msg ? res.msg : "导入失败");
                    }
                });
            }
        }
    });

    //打开审核发票页面
    function reviewInvoice(data) {
        if (data.invoiceStatus == "PASS") {
            top.layer.alert("发票已经审核通过，不能再次审核");
            return;
        }
        var customHouse = data.customHouse;
        if (!customHouse) {
            customHouse = "";
        }
        var index = layui.layer.open({
            title: "审核发票",
            type: 2,
            area: [850 + 'px', (maxHeight - 10) + 'px'],
            shade: 0.4,
            btnAlign: 'r',
            id: "review_invoice", //设定一个id，防止重复弹出
            content: "invoiceReview.html?customHouse=" + customHouse + "&imgFilePath=" + data.invoiceImg,
            success: function () {
                var body = layui.layer.getChildFrame('body', index);
                body.find("input[name=id]").val(data.id).attr("readonly", true);//标识是修改还是新增
                if (data.invoice) {
                    body.find("input[name=invoice]").val(data.invoice).attr("readonly", false);
                    body.find("input[name=invoiceImg]").val(data.invoiceImg).attr("readonly", false);
                }
                body.find("input[name=dateDeDepense]").val(data.dateDeDepense).attr("readonly", true);
                body.find("input[name=fournisseur]").val(data.fournisseur).attr("readonly", true);
                if (data.invoiceRate == "other") {
                    body.find("#invoiceRateRadioThree").attr("checked", "checked").attr("readonly", true);
                    body.find("input[name=invoiceMoney]").css({"color": "red"});
                } else if (data.invoiceRate == "20%") {
                    body.find("#invoiceRateRadioOne").attr("checked", "checked").attr("readonly", true);
                    body.find("input[name=invoiceMoney]").css({"color": "blue"});
                } else {
                    body.find("#invoiceRateRadioTwo").attr("checked", "checked").attr("readonly", true);
                    body.find("input[name=invoiceMoney]").css({"color": "red"});
                }
                body.find("input[name=montantTTC]").val(parseFloat(data.montantTTC).toFixed(2)).attr("readonly", true);
                body.find("input[name=invoiceMoney]").val(data.invoiceMoney);
                form.render();
                setTimeout(function () {
                    layui.layer.tips('点击此处返回发票列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500);
            }
        });
    }

    function editCooperative(data) {
        var index = layui.layer.open({
            title: "修改",
            type: 2,
            area: [850 + 'px', 300 + 'px'],
            shade: 0.4,
            btnAlign: 'r',
            id: "update_Cooperative", //设定一个id，防止重复弹出
            content: "updateCooperative.html?fournisseur=" + data.fournisseur + "&jobNumber=" + data.jobNumber,
            success: function () {
                var body = layui.layer.getChildFrame('body', index);
                body.find("input[name=id]").val(data.id);
                body.find("input[name=montantTTC]").val(data.montantTTC);
                form.render();
                setTimeout(function () {
                    layui.layer.tips('点击此处返回发票列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500);
            },
            end: function () {
                console.log("-------close");
                $(".search_btn").click();
            }
        });
    }

    //列表操作
    table.on('tool(list)', function (obj) {
        var layEvent = obj.event,
            data = obj.data;
        if (layEvent === 'viewInvoice') { //查看发票
            uploadInvoice(data, true);
        } else if (layEvent === 'uploadInvoice') { //上传发票
            uploadInvoice(data, false);
        } else if (layEvent === 'reviewInvoice') { //审核发票
            reviewInvoice(data);
        } else if (layEvent === 'editCooperative') {
            editCooperative(data);
        }
    });

    //处理权限相关的东西
    function handlePrivage() {
        //判断是否有查看所有数据的权限，如果没有，则隐藏所有员工的这项搜索条件
        if (baseConfig.checkPrivalege(baseConfig.CONSUMER_LIST_ALL)) {
            $("#importUserIdDiv").show();
            $("#reviewStartTime").show();
            $("#reviewEndTime").show();
        } else {
            $("#importUserIdDiv").hide();
            $("#reviewStartTime").hide();
            $("#reviewEndTime").hide();
        }
        //判断是否有导入/导出excel数据的权限
        if (baseConfig.checkPrivalege(baseConfig.CONSUMER_EXCEL)) {
            $("#download_moden").show();
            $("#import_excel_a").show();
            $("#export_excel_btn").show();
            $("#download_invoice").show();
            $("#download_excel").show();
            $("#merge_btn").show();
            $("#partition_btn").show();
        } else {
            $("#download_moden").hide();
            $("#import_excel_a").hide();
            $("#export_excel_btn").hide();
            $("#download_invoice").hide();
            $("#download_excel").hide();
            $("#merge_btn").hide();
            $("#partition_btn").hide();
        }
    }

    function getSearchParam() {
        var importUserId = $("input[name=importUserId]").val();
        var money = $("input[name=money]").val();
        var dealMonth = $("select[name=dealMonth]").val();
        var dealStartTime = $("input[name=dealStartTime]").val();
        var dealEndTime = $("input[name=dealEndTime]").val();
        var reviewStartTime = $("input[name=reviewStartTime]").val();
        var reviewEndTime = $("input[name=reviewEndTime]").val();
        var carteIdentifiant = $("input[name=carteIdentifiant]").val();
        var jobNumber = $("input[name=jobNumber]").val();
        var invoiceStatus = $("select[name=invoiceStatus]").val();
        var red = $("select[name=red]").val();
        var cooperativeSimpleName = $("input[name=cooperativeSimpleName]").val();

        var param = {
            "importUserId": importUserId,
            "money": money,
            "dealMonth": dealMonth,
            "dealStartTime": dealStartTime,
            "dealEndTime": dealEndTime,
            "carteIdentifiant": carteIdentifiant,
            "jobNumber": jobNumber,
            "reviewStartTime": reviewStartTime,
            "reviewEndTime": reviewEndTime,
            "invoiceStatus": invoiceStatus,
            "cooperativeSimpleName": cooperativeSimpleName,
            "red": red,
        };
        return param;
    }

    //添加
    $(".add_btn").click(function () {
        showBaseInfo(null, false);
    });

    //添加/修改/详细查看（readonly=true）
    function showBaseInfo(data, readonly) {
        console.log('showBaseInfo')
        var index = layui.layer.open({
            title: "信息编辑",
            type: 2,
            area: [600 + 'px', (maxHeight < 400 ? maxHeight - 10 : 400) + 'px'],
            shade: 0.4,
            btnAlign: 'r',
            id: "consumer_ADD", //设定一个id，防止重复弹出
            content: "baseFormData.html",
            success: function () {
                var body = layui.layer.getChildFrame('body', index);
                if (data) {
                    body.find("input[name=id]").val(data.id).attr("readonly", readonly);//标识是修改还是新增

                    // body.find( "input[name=phone]").val( data.phone).attr( "readonly", readonly);
                    // body.find( "input[name=nom]").val( data.nom).attr( "readonly", readonly);
                    // body.find( "input[name=prenom]").val( data.prenom).attr( "readonly", readonly);
                    // body.find( "input[name=email]").val( data.email).attr( "readonly", readonly);

                    body.find("input[name=jobNumber]").val(data.jobNumber).attr("readonly", readonly);
                    if (readonly) {
                        body.find("#submitDiv").hide();
                    }
                }
                form.render();
                setTimeout(function () {
                    layui.layer.tips('点击此处返回数据列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500);
            }
        });
    }

    //删除
    $(".delete_btn").on("click", function () {
        console.log("delete_btn")
        var checkStatus = table.checkStatus('listTable'),
            data = checkStatus.data;
        if (data.length > 0) {
            var ids = "";
            for (var i = 0; i < data.length; i++) {
                ids += data[i].id;
                if (i != data.length - 1) {
                    ids += ",";
                }
            }
            del(ids);
        } else {
            top.layer.msg("请选择需要删除的数据");
            return;
        }
    });

    //删除
    function del(ids) {
        layer.confirm('确定删除选中的数据项？', {icon: 3, title: '提示信息'}, function (index) {
            $.post("/consumer/del", {
                "ids": ids
            }, function (res) {
                if (res.code == 200) {
                    tableIns.reload();
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                } else {
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                }
            });
        });
    }
});
